V=$(shell cat VERSION)
P=$(shell pwd)
T=$(shell sed -n '1p' .env)
L=$(shell sed -n '2p' .env)
O=$(shell sed -n '3p' .env)
M=$(shell sed -n '4p' .env)
K=$(shell sed -n '5p' .env)
H=$(shell sed -n '6p' .env)

.PHONY: install
install:
	pip install -i https://pypi.tuna.tsinghua.edu.cn/simple \
		--extra-index-url https://download.pytorch.org/whl \
		-r requirements.txt

.PHONY: runserver
runserver:
	docker run -itd --name bot-server -p $(O):$(O) \
		-e WECHATY_LOG='verbose' \
		-e WECHATY_PUPPET=$(L) \
		-e WECHATY_PUPPET_PADLOCAL_TOKEN=$(T) \
		-e WECHATY_PUPPET_SERVER_PORT=$(O) \
		-e WECHATY_TOKEN=$(K) \
		wechaty/wechaty:0.65

.PHONY: runbot
runbot:
	docker run -it --name bot-py \
		--gpus all -p 8004:8004 \
		-v $(P)$(M):/models -v $(P)/main:/bot/main \
		-e WECHATY_PUPPET=$(L) \
		-e WECHATY_PUPPET_SERVICE_TOKEN=$(T) \
		-e WECHATY_PUPPET_SERVICE_ENDPOINT='$(H):$(O)' \
		-e WECATY_TOKEN=$(K) \
		chatbot-py:$(V)

.PHONY: run
run: runserver runbot
	echo 'Running...'

.PHONY: build
build:
	docker build -t chatbot-py:$(V) .
